﻿// Operations and events related to tracking a previous value of an element
define([
    'Wjs/Wjs'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'ValueWatcher',

        isModified: function () {

            return this.getValue() != this.previousValue;
        },

        acceptChanges: function () {

            this.previousValue = this.getValue();

            return this;
        },

        fireFieldChanged: function (evt) {
            var form = this.getForm();

            if (form && form.fieldChangedHandler) {

                form.fieldChangedHandler(this);
            }

            if (this.changeHandler) {

                this.changeHandler(evt);
            }
        },

    });

});